package com.villaday.idf.activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.google.gson.Gson;
import com.villaday.idf.R;
import com.villaday.idf.adapter3.OrderAdapter;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.BaseActivity;
import com.villaday.idf.model3.OrderListEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.LogUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.ToolBarUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

public class OrderActivity extends BaseActivity {


    @BindView(R.id.toolbar_back)
    ImageButton toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar_next)
    TextView toolbarNext;
    @BindView(R.id.Line_view)
    View LineView;
    @BindView(R.id.toolbar_text)
    Toolbar toolbarText;
    @BindView(R.id.rv_od)
    RecyclerView rvOd;


    private List<OrderListEntity.BodyBean.ListBean> mList;

    @Override
    protected int getViewResId() {
        return R.layout.activity_order;
    }

    @Override
    protected void init() {
        super.init();
        ToolBarUtil.initToolBar(toolbarText, "订单详情", new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        initRecycle();

        getOrder();
    }

    private void getOrder() {
        Map<String, String> map = new HashMap<>();
        OkHttpUtil.getJSON(this, Constant.URL.createOrders, map, new OkHttpUtil.OnDataListener() {



            @Override
            public void onResponse(String url, String json) {
                LogUtil.jLog().e(json);
                OrderListEntity orderListEntity = new Gson().fromJson(json, OrderListEntity.class);
                if (orderListEntity.getCode().equals(Constant.Strings.SUC)){
                    mList = orderListEntity.getBody().getList();
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }


    /**
     * 初始化列表
     */
    private void initRecycle() {
        rvOd.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        OrderAdapter orderAdapter = new OrderAdapter(this);
        rvOd.setAdapter(orderAdapter);
        List list = new ArrayList();
        list.add("已完成");
        list.add("已取消");
        list.add("退款中");
        list.add("已退款");
        list.add("待支付");
        list.add("确认中");
        list.add("待使用");
        orderAdapter.setData(list);


        orderAdapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                startActivity(OrderDetailsActivity.class);
            }
        });
    }


}